package org.starsource.forum.client.domain;

import java.util.ArrayList;
import java.util.List;

import org.starsource.forum.client.util.Assertion;
import com.google.gwt.user.client.rpc.IsSerializable;

public class CategoryObject implements IsSerializable {

	private int id;
	
	private CategoryObject parent;
	
	private String name;
	
	private String caption;
	
	private List<CategoryObject> children = new ArrayList<CategoryObject>();
	
	public CategoryObject() {
	}
	
	public CategoryObject(CategoryObject parent, String name, String caption) {
		this.parent = parent;
		this.name = name;
		this.caption = caption;
	}
	
	public CategoryObject(int id, CategoryObject parent, String name, String caption) {
		this.id = id;
		this.parent = parent;
		this.name = name;
		this.caption = caption;
	}
	
	@Override
	public boolean equals(Object obj) {
		try {
			CategoryObject object = (CategoryObject)obj;
			
			if (this.id != object.getId()) return false;
			
			if (!Assertion.isEqual(this.parent, object.parent)) return false;
			
			if (!Assertion.isEqual(this.name, object.name)) return false;
			
			if (!Assertion.isEqual(this.caption, object.caption)) return false;

			return true;
		} catch (Exception e) {
			return false;
		}
	}

	public int getId() {
		return this.id;
	}
	
	public void setId(int id) {
		this.id = id;
	}
	
	public CategoryObject getParent() {
		return this.parent;
	}
	
	public void setParent(CategoryObject parent) {
		this.parent = parent;
	}
	
	public String getName() {
		return this.name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public String getCaption() {
		return this.caption;
	}
	
	public void setCaption(String caption) {
		this.caption = caption;
	}
	
	public List<CategoryObject> getChildren() {
		return this.children;
	}
	
	public void setChildren(List<CategoryObject> children) {
		this.children = children;
	}

}
